package com.taotao.thread.Test1;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author wangjin
 * @title: T05_ReentrantLock5
 * @projectName thread
 * @description: TODO
 * @date 2022/5/4 0004 9:11
 */
public class T05_ReentrantLock5  extends Thread{
    private  static  ReentrantLock lock = new ReentrantLock(false);

    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName()+"获得锁");
            }finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) {
        T05_ReentrantLock5 r1 = new T05_ReentrantLock5();
        Thread t15=new Thread(r1);
        Thread t2=new Thread(r1);
        t15.start();
        t2.start();
    }
}
